# llvm 目录
#  /zion0/git_proj/llvm-project-llvmorg-18.1.0/

mkdir -p /zion0/etc/ssh
cat > /zion0/etc/ssh/ssh_config <<"EOF"
Host *
  StrictHostKeyChecking no
EOF

cat > /zion0/git_proj/l2_nvfs_distcc_pump_ninja_build_llvm.sh << "EOF"
set -eux

build_core=204

# DISTCC_POTENTIAL_HOSTS
export DISTCC_HOSTS="node02/23,lzo,cpp node03/23,lzo,cpp mstor01/79,lzo,cpp mstor02/79,lzo,cpp"

build_base='/zion0/git_proj/l2_nvfs_distcc_pump_ninja_build_llvm'

build_llvm=${build_base}/build-llvm
build_clang=${build_base}/build-clang
installprefix=${build_base}/install
llvm=/zion0/git_proj/llvm-project-llvmorg-18.1.0/

rm -rf $build_llvm || echo 0
mkdir -p $build_llvm
mkdir -p $installprefix


# start distcc-pump
eval `/usr/local/bin/pump --startup`

cd  $llvm/llvm 
time cmake \
    -G Ninja -S $llvm/llvm -B $build_llvm \
    -D CMAKE_C_COMPILER_LAUNCHER=/usr/local/bin/distcc -D CMAKE_CXX_COMPILER_LAUNCHER=/usr/local/bin/distcc \
    -DLLVM_INSTALL_UTILS=ON \
    -DCMAKE_INSTALL_PREFIX=$installprefix \
    -DCMAKE_BUILD_TYPE=Release  2>&1 | tee ${build_base}/build.log

time ninja -v -C $build_llvm  -j${build_core} 2>&1 | tee ${build_base}/ninja_build.log

# stop distcc-pump
/usr/local/bin/pump --shutdown

tail -f /dev/null
EOF


mkdir -p /zion0/l2build_log
chmod 777  /zion0/l2build_log

cat > /zion0/git_proj/docker_build_l2_nvfs_distcc_pump_ninja_build_llvm.sh <<"EOF"

docker rm -f build_llvm || echo 0
docker run --name build_llvm \
    --network host \
    -v /zion0/etc/ssh/ssh_config:/etc/ssh/ssh_config:ro \
    -v /root/.ssh:/root/.ssh \
    -v /root/.config:/root/.config \
    -v /zion0/git_proj:/zion0/git_proj \
    -v  /zion0/l2build_log:/var/log \
    openeuler/openeuler:22.03-lts-sp2-llvm-ccache-distcc \
    bash /zion0/git_proj/l2_nvfs_distcc_pump_ninja_build_llvm.sh
EOF


log_file='/zion0/git_proj/l2_nvfs_distcc_pump_ninja_build_llvm.log'

nohup   bash /zion0/git_proj/docker_build_l2_nvfs_distcc_pump_ninja_build_llvm.sh 2>&1 > ${log_file} &

tail -f ${log_file}


#  grep -A5 -B3 'real' /zion0/git_proj/l2_nvfs_distcc_pump_ninja_build_llvm.log
